using System;
using System.Text.RegularExpressions;
using Toast.Core;
using Toast.Core.Interfaces;
using Toast.Extensions;

namespace Toast.ContentTypes
{
    public abstract class CssContentBase : ICssContent
    {
        ICompressionStrategy _compression = ToastCore.Compression().ForCss();

        #region ICssContent Members

        public string HttpContentType
        {
            get { return "text/css"; }
        }

        public Func<bool> InjectIf
        {
            get; set;
        }

        public string Id
        {
            get { return Regex.Replace(FileName, @"[\\\/\.\?\&\s]", ""); }
        }

        public string FileName { get; set; }

        public virtual InjectAt InjectAt { get; set; }

        public abstract IInjectionFormatter GetFormatter(string packageKey);

        public virtual ICompressionStrategy Compression
        {
            get { return _compression; }
            set { _compression = value; }
        }

        public abstract bool TryConstructFrom(string from, out IContent result);

        #endregion

        protected string GenerateFileName()
        {
            return ShortGuid.NewGuid();
        }
    }
}